from common.Base import open_browser, Base
import time

PR_url = "http://localhost:8080/ecshop/user.php?act=qpassword_name"


class PasswordRecovery_page(Base):
    user_name_loc = ("name", "user_name")  # 定位用户名输入框
    submit_loc = ("name", "submit")  # 定位提交按钮
    passwd_answer_loc = ("name", "passwd_answer")  # 定位密码问题答案
    p = ("css selector", "td[colspan='2'] > strong")  # 请根据您注册时设置的密码问题输入设置的答案 #请输入您注册的用户名以取得您的密码提示问题。
    submit1_loc = ("name", "submit")  # 定位问题答案 提交按钮
    new_password_loc = ("name", "new_password")  # 定位新密码
    confirm_password_loc = ("name", "confirm_password")  # 定位确认新密码
    button_loc = ("name", "button")  # 返回上一页按钮定位

    def p_text(self):
        return self.get_element_text(self.p)

    def input_username(self, name):
        """
        输入需要找回密码的 用户名
        :param name:
        :return:
        """
        self.send_text(self.user_name_loc, name)
        self.click(self.submit_loc)

    def input_answer(self, answer):
        """
        输入 密保问题 答案
        :param answer:
        :return:
        """
        self.send_text(self.passwd_answer_loc, answer)
        self.click(self.submit1_loc)

    def inupt_newpassword(self, password):
        """
        输入 新密码
        :param password:
        :return:
        """
        self.send_text(self.new_password_loc, password)

    def inupt_confirmpassword(self, password):
        """
        输入 确认密码
        :param password:
        :return:
        """
        self.send_text(self.confirm_password_loc, password)

    def cilck_submit(self):
        """
        点击确认
        :return:
        """
        self.click(self.submit_loc)

    def click_button(self):
        """
        点击 返回上一页
        :return:
        """
        self.click(self.button_loc)


if __name__ == '__main__':
    driver = open_browser()
    lp = PasswordRecovery_page(driver)
    lp.open_url(PR_url)
    lp.input_username("admin123")
    lp.input_answer("睡觉")
    lp.inupt_newpassword("123456789")
    lp.inupt_confirmpassword("3456789")
    lp.cilck_submit()
